<script type="text/javascript">
$(function() {
	 $(document).ready(function () {
	 var crc = $("#code").val();
	 $('#calendar').fullCalendar({
			defaultView: 'month',
			allDayText:'全天',
			theme: false,
	        header: {
	           left: 'prev,next today',
	           center: 'title',
	           right: 'month,agendaWeek,agendaDay'
	        },
	        monthNames: ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"],
	        monthNamesShort: ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"],
	        dayNames: ["周日", "周一", "周二", "周三", "周四", "周五", "周六"],
	        dayNamesShort: ["周日", "周一", "周二", "周三", "周四", "周五", "周六"],
	        today: ["今天"],
	        firstDay: 1,
	        axisFormat:'HH(:mm)tt',
	        minTime:7,
	        maxTime:24,
	        buttonText: {
	            today: '今天',
	            month: '月',
	            week: '周',
	            day: '日'
	        },
	        selectable: true,
			selectHelper: true,
			select: function(start, end, allDay) {//选择时间时 
	           	var parm = {'start':($.fullCalendar.formatDate(start,'yyyy-MM-dd HH:mm:ss')), 'end':($.fullCalendar.formatDate(end,'yyyy-MM-dd HH:mm:ss')), 'allDay':allDay, 'crc':crc};
	        	var url = create_url('classRoom-aidInit');
	        	$.colorbox({overlayClose:false, href:url, data:parm, close:'[关闭]', width:'800px', height:'600px', open:true});
			},
			events: function(start, end, callback){//加载数据
				var events = [];
				var parm = {'crc':crc};
				var url = create_url('classRoom-showClassRoomItem');
				$.ajax({type:'POST', url:url, data:parm,
					success: function(result) {
						var items = result;
						for (var i in items) {
							events.push({
								title:items[i].title == null || items[i].title == '' ? '无标题':items[i].title,
								start:$.fullCalendar.parseDate(items[i].startTime),
								end:$.fullCalendar.parseDate(items[i].endTime),
								allDay:items[i].allDay,
								id:items[i].code,
							});
						}
						callback(events);
					}
				});
		    },
		    slotEventOverlap:false,//事件不可重叠
		    editable:true,//是否可拖拽移动
		    eventDrop: function(event, dayDelta, minuteDelta, allDay, revertFunc) {//拖拽移动时间时
				$.Zebra_Dialog('移动到这吗？',{
					'type': 'question','title': '警告' ,'buttons':[
			           {caption:'确定',callback:function() {
						var parm = {'code':event.id, 'allDay':event.allDay, 'start':($.fullCalendar.formatDate(event.start, 'yyyy-MM-dd HH:mm:ss')), 'end':($.fullCalendar.formatDate(event.end, 'yyyy-MM-dd HH:mm:ss'))};
						var url = create_url('classRoom-updClassRoomItem');
		            	$.ajax({type:'POST', url:url, data:parm,
							success: function(result) {
								if(result == 'success'){
										sys_msg("操作成功!");
									}else{
										sys_msg("拖拽失败，请刷新后重试!");
										revertFunc();
									}
								}
							});
			    		}},
			           {caption:'取消',callback:function(){}
			    	}]
				});
		    },
		    dragRevertDuration: 500,//拖拽不成功时恢复
		    eventResize: function(event, dayDelta, minuteDelta, revertFunc, jsEvent, ui, view) {//改变时间长度时
		     $.Zebra_Dialog('移动到这吗？',{
				'type': 'question','title': '警告' ,'buttons':[
			           {caption:'确定',callback:function() {
						var parm = {'code':event.id, 'allDay':event.allDay, 'start':($.fullCalendar.formatDate(event.start, 'yyyy-MM-dd HH:mm:ss')), 'end':($.fullCalendar.formatDate(event.end, 'yyyy-MM-dd HH:mm:ss'))};
		            	var url = create_url('classRoom-updClassRoomItem');
		            	$.ajax({type:'POST', url:url, data:parm,
							success: function(result) {
								if(result == 'success'){
										sys_msg("操作成功!");
									}else{
										sys_warning("拖拽失败，请刷新后重试!");
										revertFunc();
									}
								}
							});
			    		}},
			           {caption:'取消',callback:function(){}
			    	}]
				});
		    },
		    eventClick: function(calEvent, jsEvent, view) {//点击事件时
		    	console.log(calEvent)
		    	var parm = {'code':calEvent.id};
            	var url = create_url('classRoom-aidInit');
            	$.colorbox({overlayClose:false, href:url, data:parm, close:'[关闭]', width:'800px', height:'600px', open:true});
		        //$(this).css('border-color', 'red');改变点击后的样式
		    },
		});
	 });
});	
</script>
<#import "/freemarker/modeltype.ftl" as mt>
<#import "/freemarker/modeltype_entity.ftl" as mte>
<div class="panel panel-default" style="float: left;">
	<form id="editClassRoomForm">
			<table class="table table-bordered" style="width: 400px;">
				<tr>
					<td style="width: 80px">教室名称</td>
					<td>
						<input type="text" name="name" value="${(cr.name)!''}" />
						<input type="hidden" id="code" name="code" value="${(cr.code)!''}" />
					</td>
				</tr>
				<tr>
					<td>地址</td>
					<td>
						<input type="text" name="address" value="${(cr.address)!''}" />
					</td>
				</tr>
				<tr height="40">
					<td colspan="2" style="text-align: center;">
						<a href="javascript:;" class="btn btn-info" onclick="javascript: sys_load_handle('classRoom'); return false;"><i class="icon-save"></i>&nbsp;保&nbsp;&nbsp;存</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
						<a href="javascript:;" class="btn btn-primary" onclick="javascript: sys_load_handle('classRoom');return false;"><i class="fontello-icon-block"></i>&nbsp;取&nbsp;&nbsp;消</a>
					</td>
				</tr>
			</table>
		</div>
	</from>
</div>
<div id="calendar" style="width: 700px;height: 600px;float: left;"></div>